package com.ruoyi.local.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.local.domain.SysAppSidemenu;
import com.ruoyi.local.service.ISysAppSidemenuService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 侧边菜单配置Controller
 * 
 * @author ruoyi
 * @date 2020-12-21
 */
@Controller
@RequestMapping("/local/sidemenu")
public class SysAppSidemenuController extends BaseController
{
    private String prefix = "local/sidemenu";

    @Autowired
    private ISysAppSidemenuService sysAppSidemenuService;

    @RequiresPermissions("local:sidemenu:view")
    @GetMapping()
    public String sidemenu()
    {
        return prefix + "/sidemenu";
    }

    /**
     * 查询侧边菜单配置列表
     */
    @RequiresPermissions("local:sidemenu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysAppSidemenu sysAppSidemenu)
    {
        startPage();
        List<SysAppSidemenu> list = sysAppSidemenuService.selectSysAppSidemenuList(sysAppSidemenu);
        return getDataTable(list);
    }

    /**
     * 导出侧边菜单配置列表
     */
    @RequiresPermissions("local:sidemenu:export")
    @Log(title = "侧边菜单配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysAppSidemenu sysAppSidemenu)
    {
        List<SysAppSidemenu> list = sysAppSidemenuService.selectSysAppSidemenuList(sysAppSidemenu);
        ExcelUtil<SysAppSidemenu> util = new ExcelUtil<SysAppSidemenu>(SysAppSidemenu.class);
        return util.exportExcel(list, "sidemenu");
    }

    /**
     * 新增侧边菜单配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存侧边菜单配置
     */
    @RequiresPermissions("local:sidemenu:add")
    @Log(title = "侧边菜单配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysAppSidemenu sysAppSidemenu)
    {
        return toAjax(sysAppSidemenuService.insertSysAppSidemenu(sysAppSidemenu));
    }

    /**
     * 修改侧边菜单配置
     */
    @GetMapping("/edit/{menuId}")
    public String edit(@PathVariable("menuId") Long menuId, ModelMap mmap)
    {
        SysAppSidemenu sysAppSidemenu = sysAppSidemenuService.selectSysAppSidemenuById(menuId);
        mmap.put("sysAppSidemenu", sysAppSidemenu);
        return prefix + "/edit";
    }

    /**
     * 修改保存侧边菜单配置
     */
    @RequiresPermissions("local:sidemenu:edit")
    @Log(title = "侧边菜单配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysAppSidemenu sysAppSidemenu)
    {
        return toAjax(sysAppSidemenuService.updateSysAppSidemenu(sysAppSidemenu));
    }

    /**
     * 删除侧边菜单配置
     */
    @RequiresPermissions("local:sidemenu:remove")
    @Log(title = "侧边菜单配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysAppSidemenuService.deleteSysAppSidemenuByIds(ids));
    }
}
